<!-- added by fq -->
<%= javascript_include_tag "ichart.1.2.min" %>
<%#= javascript_include_tag "jquery-1.8.3-ui-1.9.2-ujs-2.0.3" %>
<%= stylesheet_link_tag "sec-analysis.css" %>
<%= stylesheet_link_tag "buglist-ichart.css" %>
<%= stylesheet_link_tag "buglist.css" %>

<%= javascript_include_tag "jquery.min" %>
<%= javascript_include_tag "bootstrap.min" %>

<%= javascript_include_tag "highcharts", "highcharts-more" %>

<%= javascript_include_tag "echarts/dist/echarts.js" %>

<script type="text/javascript">
	$(document).ready(function() {
	 	var osp_id = <%=@open_source_project.id%>;
	    $("#nav li a").click(function() {
	    	var ajax_url = "";
	        //$("#myTabContent").empty().append("<div id='loading'><#%= image_tag('../images/loading.gif') %></div>");
	       	if(this.name == 'show_memos_tab'){
	       		$("#analysis_tab").removeClass('active');
	       		$("#memos_tab").addClass('active');
	   			ajax_url = '/tabs/show_memos_tab?osp_id=';
	   		}
	   		else{
	   			$("#memos_tab").removeClass('active');
	   			$("#analysis_tab").addClass('active');
	   			ajax_url = '/tabs/show_analysis_tab?osp_id=';
	   		}
	        $.ajax({ url: ajax_url + osp_id, success: function(html) {
	            $("#myTabContent").empty().append(html);
	            }
	    });
	    	return false;
	    });

    //$("#myTabContent").empty().append("<div id='loading'><#%= image_tag('../images/loading.gif') %></div>");
    $.ajax({ url: '/tabs/show_memos_tab?osp_id=' + osp_id, success: function(html) {
			$("#myTabContent").empty().append(html);
	}
	});
	});
</script>
<%#####################导航条########################%>

<div id="analysis_left_bar" style="float: left; width: 72%; border:1px solid rgb(225,225,225);">
  <ul id="nav" class="nav nav-tabs">
		<li id="memos_tab" class="active">
			<a name="show_memos_tab" href='javascript:void(0)' data-toggle="tab"> 全球热帖 </a>
		</li>
		<li id="analysis_tab">
			<a name="show_analysis_tab" href="javascript:void(0)" data-toggle="tab"> 软件态势 </a>
		</li>
	</ul>

  <div id="myTabContent" class="tab-content">
    
  </div>
</div>


<div id="analysis_right_bar" style="float: right; width: 26%; border:1px solid rgb(225,225,225);">
<!--  
<div id="similarity_recommendation">
    <div class="recommondation_title">相似软件推荐</div>
    <ul class="recommondation_projects_list">
      <% if @simility_osp_array!=nil %>
          <% for i in 0..@simility_osp_array.length-1 %>
              <li>
                <p>
                  <%= link_to @simility_osp_array[i].name, open_source_project_path(@simility_osp_array[i]), :onclick => "return user_trace_click_similar_project(this,'#{i+1}','#{request.session_options[:id]}');" %>
                  <span style="float: right; margin-left: 8px"><button id='down_hand_button' type="button" style="background: none; border: none" onclick = "user_trace_click_similar_project_down(this,'<%=@simility_osp_array[i].id %>','<%=i+1 %>','<%=request.session_options[:id] %>');"><img src="/images/down_hand.png" width="15px" /></button></span>
                  <span style="float: right"><button id='up_hand_button' type="button" style="background: none; border: none" onclick = "user_trace_click_similar_project_up(this,'<%=@simility_osp_array[i].id %>','<%=i+1 %>','<%=request.session_options[:id] %>');"><img src="/images/up_hand.png" width="15px" /></button></span>
                </p>
                <%= @simility_osp_des[i] %>
                <hr style="margin-top: 5px; margin-bottom: 0px; width: 99.5%;">
              </li>
          <% end %>
      <% end %>
    </ul>
  </div>
-->
  <div id="relation_recommendation" style="margin-top: 20px;">
    <div class="recommondation_title">相关软件推荐</div>
    <ul class="recommondation_projects_list">
      <% if @relation_osp_array!=nil %>
          <% for i in 0..@relation_osp_array.length-1 %>
              <li>
                <p>
                  <%= link_to @relation_osp_array[i].name, open_source_project_path(@relation_osp_array[i]), :onclick => "return user_trace_click_related_project(this,'#{i+1}','#{request.session_options[:id]}');" %>
                </p>
                <%= @relation_osp_des[i] %>
                <hr style="margin-top: 5px; margin-bottom: 0px; width: 99.5%;">
              </li>
          <% end %>
      <% end %>
    </ul>
  </div>


</div>

<script type="text/javascript">
    $(function () {
        //相似软件推荐图表
        <% if @simility_osp_array.nil? %>
        $('echarts_simility').html('没有任何数据');
        <% else %>
        // 路径配置
        require.config({
            paths: {
                echarts: 'http://echarts.baidu.com/build/dist'
            }
        });

        // 使用
        require(
                [
                    'echarts',
                    'echarts/chart/force',
                    'echarts/chart/chord'
                ],
                function (ec) {
                    var myChart = ec.init(document.getElementById('echarts_simility'));

                    var option = {
                        tooltip: {
                            trigger: 'item',
                            formatter: '{a} : {b}'
                        },
                        toolbox: {
                            show: false
                        },
                        series: [
                            {
                                type: 'force',
                                name: '项目关联',
                                ribbonType: true,
                                categories: [
                                    {
                                        name: '项目'
                                    },
                                    {
                                        name: '相关项目'
                                    }
                                ],
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            textStyle: {
                                                color: '#333'
                                            }
                                        },
                                        nodeStyle: {
                                            brushType: 'both',
                                            borderColor: 'rgba(255,215,0,0.4)',
                                            borderWidth: 1
                                        },
                                        linkStyle: {
                                            type: 'curve',
                                            color: '#5182ab',
                                            width: 1
                                        }
                                    },
                                    emphasis: {
                                        label: {
                                            show: false
                                        },
                                        nodeStyle: {

                                        },
                                        linkStyle: {}
                                    },
                                },//itemStyle结尾
                                useWorker: false,
                                minRadius: 15,
                                maxRadius: 25,
                                gravity: 1.1,
                                scaling: 1.1,
                                // roam:'move', 不能整体拖动
                                nodes: [
                                    {category: 0, name: '<%= OpenSourceProject.find(@simility_id_array[0]).name.to_s %>', value: 10},
                                    <% @simility_osp_array.each do |simility_osp| %>
                                    {category: 1, name: '<%=simility_osp.name %>', value: 5},
                                    <% end %>
                                ],
                                links: [
                                    <% for i in 0..@simility_osp_array.length-1 %>
                                    {source: '<%=@simility_osp_array[i].name %>', target: '<%= OpenSourceProject.find(@simility_id_array[0]).name.to_s %>', weight: '<%=@simility_weight_array[i].to_s %>'},
                                    <% end %>
                                ]
                            }//series第一个大括号
                        ]//series结尾
                    };
                    myChart.setOption(option);
                    var ecConfig = require('echarts/config');

                    function focus(param) {
                        var data = param.data;
                        var links = option.series[0].links;
                        var nodes = option.series[0].nodes;
                        if (
                                data.source !== undefined
                                        && data.target !== undefined
                                ) { //点击的是边
                            var sourceNode = nodes.filter(function (n) {
                                return n.name == data.source
                            })[0];
                            var targetNode = nodes.filter(function (n) {
                                return n.name == data.target
                            })[0];
                            // console.log("选中了边 " + sourceNode.name + ' -> ' + targetNode.name + ' (' + data.weight + ')');
                        } else { // 点击的是点
                            // console.log("选中了" + data.name + '(' + data.value + ')');
                            //根据name查找对应的项目id
                            var name = data.name;
                            //js在服务器中查询项目名对应的项目id
                            $.ajax({
                                type: "post",
                                contentType: "application/json; charset=utf-8",
                                url: '/echarts/ajax?chart=simility&name=' + name,
                                dataType: "json",
                                success: jumpUrl,
                                error: function errorCallback(XMLHttpRequest, textStatus, errorThrown) {
                                    alert(errorThrown + ":" + textStatus);
                                }
                            });
                        }
                    }

                    myChart.on(ecConfig.EVENT.CLICK, focus)

                    myChart.on(ecConfig.EVENT.FORCE_LAYOUT_END, function () {
                        console.log(myChart.chart.force.getPosition());
                    });
                }//function结尾
        );//require结尾


        <% end %>


        //相关软件推荐图表
        <% if @relation_osp_array.nil? %>
        $('echarts_relation').html('没有任何数据');
        <% else %>
        // 路径配置
        require.config({
            paths: {
                echarts: 'http://echarts.baidu.com/build/dist'
            }
        });

        // 使用
        require(
                [
                    'echarts',
                    'echarts/chart/force',
                    'echarts/chart/chord'
                ],
                function (ec) {
                    var myChart = ec.init(document.getElementById('echarts_relation'));

                    var option = {
                        tooltip: {
                            trigger: 'item',
                            formatter: '{a} : {b}'
                        },
                        toolbox: {
                            show: false
                        },
                        series: [
                            {
                                type: 'force',
                                name: '项目关联',
                                ribbonType: true,
                                categories: [
                                    {
                                        name: '项目'
                                    },
                                    {
                                        name: '相关项目'
                                    }
                                ],
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            textStyle: {
                                                color: '#333'
                                            }
                                        },
                                        nodeStyle: {
                                            brushType: 'both',
                                            borderColor: 'rgba(255,215,0,0.4)',
                                            borderWidth: 1
                                        },
                                        linkStyle: {
                                            type: 'curve',
                                            color: '#5182ab',
                                            width: 1
                                        }
                                    },
                                    emphasis: {
                                        label: {
                                            show: false
                                        },
                                        nodeStyle: {

                                        },
                                        linkStyle: {}
                                    },
                                },//itemStyle结尾
                                useWorker: false,
                                minRadius: 15,
                                maxRadius: 25,
                                gravity: 1.1,
                                scaling: 1.1,
                                // roam:'move', 不能整体拖动
                                nodes: [
                                    {category: 0, name: '<%= OpenSourceProject.find(@relation_id_array[0]).name.to_s %>', value: 10},
                                    <% @relation_osp_array.each do |relation_osp| %>
                                    {category: 1, name: '<%=relation_osp.name %>', value: 5},
                                    <% end %>
                                ],
                                links: [
                                    <% for i in 0..@relation_osp_array.length-1 %>
                                    {source: '<%=@relation_osp_array[i].name %>', target: '<%= OpenSourceProject.find(@relation_id_array[0]).name.to_s %>', weight: '<%=@relation_weight_array[i].to_s %>'},
                                    <% end %>
                                ]
                            }//series第一个大括号
                        ]//series结尾
                    };
                    myChart.setOption(option);
                    var ecConfig = require('echarts/config');

                    function focus(param) {
                        var data = param.data;
                        var links = option.series[0].links;
                        var nodes = option.series[0].nodes;
                        if (
                                data.source !== undefined
                                        && data.target !== undefined
                                ) { //点击的是边
                            var sourceNode = nodes.filter(function (n) {
                                return n.name == data.source
                            })[0];
                            var targetNode = nodes.filter(function (n) {
                                return n.name == data.target
                            })[0];
                            // console.log("选中了边 " + sourceNode.name + ' -> ' + targetNode.name + ' (' + data.weight + ')');
                        } else { // 点击的是点
                            // console.log("选中了" + data.name + '(' + data.value + ')');
                            //根据name查找对应的项目id
                            var name = data.name;
                            //js在服务器中查询项目名对应的项目id
                            $.ajax({
                                type: "post",
                                contentType: "application/json; charset=utf-8",
                                url: '/echarts/ajax?name=' + name,
                                dataType: "json",
                                success: jumpUrl,
                                error: function errorCallback(XMLHttpRequest, textStatus, errorThrown) {
                                    alert(errorThrown + ":" + textStatus);
                                }
                            });
                        }
                    }

                    myChart.on(ecConfig.EVENT.CLICK, focus)

                    myChart.on(ecConfig.EVENT.FORCE_LAYOUT_END, function () {
                        console.log(myChart.chart.force.getPosition());
                    });
                }//function结尾
        );//require结尾


        <% end %>

    }); //function的结尾（最外层）

    function jumpUrl(result) {
        id = result.osp_id;
        window.location.href = '/open_source_projects/' + id;
    }
</script>
<!-- ajax user trace zhangxunhui begin -->
<script type="text/javascript">
	function user_trace_click_similar_project(e,rank,session_id){
		//获取ids
		content = $(e).attr("href"); //获取id url
		id_similar = content.substring(22); //要跳过第一个 /open_source_projects/123 第22个字符到最后
		//获取当前项目id
		url = document.URL;
		str = "open_source_projects/"
		index = url.indexOf(str);
		id_former = null;
		if (index >= 0){
			id_former = url.substring(index + str.length);
		}
    	$.ajax({
			contentType: "application/json; charset=utf-8",
			timeout: 5000,
			url: '/user_traces/click_similar_project?osp_id_former=' + id_former + "&osp_id_similar=" + id_similar + "&rank=" + rank + "&session_id=" + session_id,
			dataType: "json"
		});
	}
</script>




<!-- ajax user trace zhangxunhui end -->

<!-- ajax user trace zhangxunhui begin -->
<script type="text/javascript">
	function user_trace_click_related_project(e,rank,session_id){
		//获取ids
		content = $(e).attr("href"); //获取id url
		id_related = content.substring(22); //要跳过第一个 /open_source_projects/123 第22个字符到最后
		//获取当前项目id
		url = document.URL;
		str = "open_source_projects/"
		index = url.indexOf(str);
		id_former = null;
		if (index >= 0){
			id_former = url.substring(index + str.length);
		}
    	$.ajax({
			contentType: "application/json; charset=utf-8",
			timeout: 5000,
			url: '/user_traces/click_related_project?osp_id_former=' + id_former + "&osp_id_related=" + id_related + "&rank=" + rank + "&session_id=" + session_id,
			dataType: "json"
		});
	}
</script>
<!-- ajax user trace zhangxunhui end -->

<!-- ajax user trace zhangxunhui begin -->
<script type="text/javascript">
	function user_trace_click_similar_project_down(e,id,rank,session_id){
		$(e).attr("disabled","disabled");
		$(e).find('img').attr("src","/images/down_hand_after_click.png");
		$(e).parent().next().find('button').attr("disabled","disabled");
		// $(e).parent().next().find('img').attr("src","/images/up_hand_after_click.png");
		//获取ids
		id_similar = id
		//获取当前项目id
		url = document.URL;
		str = "open_source_projects/"
		index = url.indexOf(str);
		id_former = null;
		if (index >= 0){
			id_former = url.substring(index + str.length);
		}
		// id_former = url.substring(43);
    	$.ajax({
			contentType: "application/json; charset=utf-8",
			timeout: 5000,
			url: '/user_traces/click_similar_project_down?osp_id_former=' + id_former + "&osp_id_similar=" + id_similar + "&rank=" + rank + "&session_id=" + session_id,
			dataType: "json"
		});
	}
</script>
<!-- ajax user trace zhangxunhui end -->

<!-- ajax user trace zhangxunhui begin -->
<script type="text/javascript">
	function user_trace_click_similar_project_up(e,id,rank,session_id){
		$(e).attr("disabled","disabled");
		$(e).find('img').attr("src","/images/up_hand_after_click.png");
		$(e).parent().prev().find('button').attr("disabled","disabled");
		// $(e).parent().prev().find('img').attr("src","/images/down_hand_after_click.png");
		//获取ids
		id_similar = id
		//获取当前项目id
		url = document.URL;
		str = "open_source_projects/"
		index = url.indexOf(str);
		id_former = null;
		if (index >= 0){
			id_former = url.substring(index + str.length);
		}
		// id_former = url.substring(43);
    	$.ajax({
			contentType: "application/json; charset=utf-8",
			timeout: 5000,
			url: '/user_traces/click_similar_project_up?osp_id_former=' + id_former + "&osp_id_similar=" + id_similar + "&rank=" + rank + "&session_id=" + session_id,
			dataType: "json"
		});
	}
</script>
<!-- ajax user trace zhangxunhui end -->
